package org.fog.json.map;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * User: 缪凯
 * Date: 12-2-3
 * Time: 下午4:54
 */
public class JsonMapPackageImp implements JsonMapPackage {
    /**
     * 本包下所有的json
     */
    private ConcurrentHashMap<String , JsonMapBody> bodies = null;

    private JsonMapCube cube = null;

    /**
     * 包的名称
     */
    private String name = null;

    public JsonMapPackageImp(String name){
        new JsonMapPackageImp(name , null);
    }

    public JsonMapPackageImp(String name, Map<String, JsonMapBody> bodies){
        if(name != null && !"".equals(name)){
            this.name = name;
            if(bodies != null && bodies instanceof ConcurrentHashMap)
                this.bodies = (ConcurrentHashMap<String, JsonMapBody>)bodies;
        }
    }

    public void setBodies(Map<String , JsonMapBody> bodies){
        if(bodies != null && bodies instanceof ConcurrentHashMap)
            this.bodies = (ConcurrentHashMap<String , JsonMapBody>)bodies;
    }

    public String getName() {
        return this.name;
    }

    public Map<String, JsonMapBody> getBodies() {
        return this.bodies;
    }

    public JsonMapBody getBody(String jsonId) {
        if(jsonId != null && !"".equals(jsonId) && this.bodies != null)
            return this.bodies.get(jsonId);
        return null;
    }

    public void setCube(JsonMapCube cube) {
        this.cube = cube;
    }

    public JsonMapCube getCube(){
        return this.cube;
    }
}
